package com.esm.pdafx.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyReceiver extends BroadcastReceiver {
    public Message message = null;

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals("com.android.server.scannerservice.broadcast")) {
            String codeTypeNameString = intent.getStringExtra("codetype");
            String codeValue = intent.getStringExtra("scannerdata");
//          String z = "Code Type:" + codeTypeNameString + "" + "Code:" + codeValue;
            //调用Message接口的方法
            if (message != null) {
                message.getMsg(codeValue);
            }
        } else if (intent.getAction().equals("com.android.server.scannerservice.broadcast2")) {
            String codeTypeNameString = intent.getStringExtra("codetype");
            String codeValue = intent.getStringExtra("scannerdata");
//          String z = "Code Type:" + codeTypeNameString + "" + "Code:" + codeValue;
            //调用Message接口的方法
            if (message != null) {
                message.getMsg("broadcast2=" + codeValue);
            }
        }  else if (intent.getAction().equals("android.intent.ACTION_DECODE_DATA")) {
            String codeValue = intent.getStringExtra("barcode_string");
            if (message != null) {
                message.getMsg(codeValue);
            }
        }
    }

    interface Message {
        public void getMsg(String str);
    }

    public void setMessage(Message message) {
        this.message = message;
    }
}